<?php
/**
 * User Controller van de Service Module
 *
 * @author Olivier Parent
 * @copyright Copyright (c) 2011 Artevelde University College Ghent
 */
class Service_UserController extends Zend_Controller_Action
{

    public function init()
    {
        // Voor AMF hebben we layout noch view nodig, het is gewoon data zonder opmaak
        $this->_helper->layout()->disableLayout();       // Layout uitschakelen
        $this->_helper->viewRenderer->setNoRender(true); // View renderer uitschakelen

        // Autoloader voor Service- en VO-klasses
        // http://framework.zend.com/manual/en/learning.autoloading.resources.html
        $loader = new Zend_Loader_Autoloader_Resource(array(
            'basePath'  => dirname(__FILE__) . '/../',
            'namespace' => null,
        ));
        $loader->addResourceType('service', 'services'     ,'Service')
               ->addResourceType('vo'     , 'valueobjects' ,'VO'     )
        ;
    }

    public function indexAction()
    {
        return $this->_helper->redirector('amf');
    }

    public function amfAction()
    {
        $server = new Zend_Amf_Server();

        if (APPLICATION_ENV == 'development') {
            $server->setProduction(false); // Errorhandling. OPGELET! Voor productie op true zetten!

            // == ZamfBrowser ==
            $filename = APPLICATION_PATH . '/../browser/ZendAmfServiceBrowser.php';
            if (file_exists($filename)) {
                require_once $filename;
                $server->setClass('ZendAmfServiceBrowser');
                ZendAmfServiceBrowser::$ZEND_AMF_SERVER = $server;
            }
            // =================
        }

        $auth = new Ahs_Amf_Auth();
        $acl = new Ahs_Acl(true);$server->setAuth($auth);

        $acl = new Ahs_Acl(true);
        $server->setAcl($acl);

        $server->setClass('Service_UserService');
        $server->setClassMap($asClass = 'UserVO', $phpClass = 'VO_User');

        error_reporting(0); // Foutmeldingen verstoren AMF, daarom zetten we ze uit.
        echo $server->handle();
    }

}
